$(function(){
    $(document).on('click','#btnSearch',function () {
    	Search(0);
    });
    $(document).on('click','#btnSearchNew',function () {
    	Search(1);
    });
    
    //订单查询
    function Search(Type){
     	var BeginTime=$("#txtdtStart").val();
     	var EndTime=$("#txtdtEnd").val();
     	if(BeginTime > EndTime)
     	{
     	    alert("开始日期不能大于结束日期");
     	    return false;
     	}
    	layui.use(['laypage', 'layer'], function(){
  		  var laypage = layui.laypage,
  		      layer = layui.layer;
  		  var nums = 8; //
  		  var data = seachData(Type);
  		  //模拟渲染
  		 var render = function(curr){
  		 var html ="", 
  		     last = curr*nums - 1;
  		     last = last >= data.length ? (data.length-1) : last;
  		     for(var i = (curr*nums - nums); i <= last; i++){
  		              	 html+="<tr>"
  		              	      +"<th>"+data[i].Name+"</th>"
  		              	      +"<th>"+data[i].Mobile+"</th>"
  		              	      +"<th>"+data[i].Sex+"</th>"
  		              	      +"<th>"+data[i].Company+"</th>"
  		              	      +"<th>"+data[i].Time+"</th>"
  		              	      +"<th>"+data[i].IOS+"</th>"
  		              	      +"</tr>";               
  		              	    }
  		              	    return html;
  		             }
  		  
  		  //调用分页
  		  laypage({
  		    cont: 'demo8'
  		    ,pages: Math.ceil(data.length/nums)  //得到总页数
  		    ,jump: function(obj){
  		      document.getElementById('itemTbody2').innerHTML = render(obj.curr);
  		    }
  		  });
  		});
        }
    
});

function seachData(Type){
	var res = {};
	         $.ajax({
	             type: "post",
	             url: contextPath+"/user_Seach.action",
	             data: {
	            	Type:$("#userType").find("option:selected").text(),
	             	Company:$("#company").find("option:selected").text(),
	             	BeginTime:$("#txtdtStart").val(),
	          	    EndTime:$("#txtdtEnd").val(),
	          	  Type:Type
	          	    
	             },
	             async: false,
	             reultType:'json',
	             error: function (request) {
	                 alert("Connection error");
	             },
	             success: function (result) {
	                      res= JSON.parse(result);
	                      alert("本次查询"+res.num+"条记录");
	                      var html="&nbsp;&nbsp;&nbsp;本次查询共:"+res.num+"条记录";
	                      $("#desc").html(html);
	                      if(res.num>0){
		                      document.getElementById('xx').style.display = "block"; 
	                      }
	                      else{
	                    	  document.getElementById('xx').style.display = "none";  
	                      }
	             }
	         });    
	         return res.data;
}
